package cn.yuanqiao.web.controller.archive.guangpanguanli;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.yuanqiao.archive.appManager.domain.YqTyc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import cn.yuanqiao.archive.guangpanguanli.domain.YqGptz;
import cn.yuanqiao.archive.guangpanguanli.service.IYqGptzService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 光盘台账Controller
 * 
 * @author sy
 * @date 2023-10-07
 */
@RestController
@RequestMapping("/archive/yqGptz")
public class YqGptzController extends BaseController
{
    @Autowired
    private IYqGptzService yqGptzService;

    /**
     * 查询光盘台账列表
     */
    @PreAuthorize("@ss.hasPermi('archive:yqGptz:list')")
    @GetMapping("/list")
    public TableDataInfo list(YqGptz yqGptz)
    {
        startPage();
        List<YqGptz> list = yqGptzService.selectYqGptzList(yqGptz);
        return getDataTable(list);
    }

    /**
     * 导出光盘台账列表
     */
    @PreAuthorize("@ss.hasPermi('archive:yqGptz:export')")
    @Log(title = "光盘台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Long[] IDs)
    {
        List<YqGptz> list = yqGptzService.exportYqGptzListByIDs(IDs);
        ExcelUtil<YqGptz> util = new ExcelUtil<YqGptz>(YqGptz.class);
        util.exportExcel(response, list, "光盘台账数据");
    }

    /**
     * 获取光盘台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:yqGptz:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yqGptzService.selectYqGptzById(id));
    }

    /**
     * 新增光盘台账
     */
    @PreAuthorize("@ss.hasPermi('archive:yqGptz:add')")
    @Log(title = "光盘台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqGptz yqGptz)
    {
        return success(yqGptzService.insertYqGptz(yqGptz));
    }

    /**
     * 修改光盘台账
     */
    @PreAuthorize("@ss.hasPermi('archive:yqGptz:edit')")
    @Log(title = "光盘台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqGptz yqGptz)
    {
        return success(yqGptzService.updateYqGptz(yqGptz));
    }

    /**
     * 删除光盘台账
     */
    @PreAuthorize("@ss.hasPermi('archive:yqGptz:remove')")
    @Log(title = "光盘台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yqGptzService.deleteYqGptzByIds(ids));
    }

    /**
     * 下载模板
     */
    @PreAuthorize("@ss.hasPermi('archive:yqTyc:importTemplate')")
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<YqGptz> util = new ExcelUtil<YqGptz>(YqGptz.class);
        util.importTemplateExcel(response, "光盘台账数据");
    }

    /**
     * 导入光盘台账列表
     * @author sy
     * @date 2023/6/14 17:31
     */
    @PreAuthorize("@ss.hasPermi('archive:yqTyc:import')")
    @Log(title = "光盘台账", businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public AjaxResult importYQTYC(MultipartFile file, Boolean updateSupport) throws Exception
    {
        if(file.isEmpty()){
            AjaxResult.error("参数错误！");
        }
        ExcelUtil<YqGptz> util = new ExcelUtil<>(YqGptz.class);
        List<YqGptz> gptzLists = util.importExcel(file.getInputStream());
        return yqGptzService.importYQGPTZ(gptzLists,updateSupport);
    }

    /**
     * 提醒领导安排相关人员对光盘台账进行备份，用于定时任务
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqdy_da:remove')")
    @Log(title = "光盘台账", businessType = BusinessType.INSERT)
    @GetMapping("/remind")
    public AjaxResult remind(@RequestParam("tenantCode") String tenantCode)
    {
        yqGptzService.remind(tenantCode);
        return AjaxResult.success();
    }
}
